using System;
using System.Configuration;
using System.Data;
using digit.Core;

namespace SMS.ServiceManager
{
    public class ServiceSportsManager
    {
        #region CONSTRUCTORS
        static ServiceSportsManager()
        {
            _data = new ServiceSportsData(Util.GetConnectionString("SMSSERVICE"));
            _error = "";
        }
        #endregion

        #region ATTRIBUTES
        private static ServiceSportsData _data;
        private static string _error;
        #endregion

        #region PROPERTIES
        public static string ErrorMessage
        {
            get
            {
                return _error;
            }
        }

        #endregion

        #region METHODS
        public static long Insert(string cmd1, string cmd2, string code1, string code2, string param1, string param2, string param3, string param4, string param5, string param6, string content1, string content2, string content3, string content4, string content5, string content6, string time1, string time2, string time3, byte msgType, byte contentType, byte numOfMsg, byte processType, string serviceId, string createdBy, DateTime createdDate, byte status)
        {
            _error = "";
            try
            {
                object[] values = new object[27];
                values[0] = Util.ReplaceNullTo(cmd1, DBNull.Value);
                values[1] = Util.ReplaceNullTo(cmd2, DBNull.Value);
                values[2] = Util.ReplaceNullTo(code1, DBNull.Value);
                values[3] = Util.ReplaceNullTo(code2, DBNull.Value);
                values[4] = Util.ReplaceNullTo(param1, DBNull.Value);
                values[5] = Util.ReplaceNullTo(param2, DBNull.Value);
                values[6] = Util.ReplaceNullTo(param3, DBNull.Value);
                values[7] = Util.ReplaceNullTo(param4, DBNull.Value);
                values[8] = Util.ReplaceNullTo(param5, DBNull.Value);
                values[9] = Util.ReplaceNullTo(param6, DBNull.Value);
                values[10] = Util.ReplaceNullTo(content1, DBNull.Value);
                values[11] = Util.ReplaceNullTo(content2, DBNull.Value);
                values[12] = Util.ReplaceNullTo(content3, DBNull.Value);
                values[13] = Util.ReplaceNullTo(content4, DBNull.Value);
                values[14] = Util.ReplaceNullTo(content5, DBNull.Value);
                values[15] = Util.ReplaceNullTo(content6, DBNull.Value);
                values[16] = Util.ReplaceNullTo(time1, DBNull.Value);
                values[17] = Util.ReplaceNullTo(time2, DBNull.Value);
                values[18] = Util.ReplaceNullTo(time3, DBNull.Value);
                values[19] = Util.ReplaceNullTo(msgType, DBNull.Value);
                values[20] = Util.ReplaceNullTo(contentType, DBNull.Value);
                values[21] = Util.ReplaceNullTo(numOfMsg, DBNull.Value);
                values[22] = Util.ReplaceNullTo(processType, DBNull.Value);
                values[23] = Util.ReplaceNullTo(serviceId, DBNull.Value);
                values[24] = createdBy;
                values[25] = Util.ReplaceNullTo(createdDate, DBNull.Value);
                values[26] = status;

                DataTable dTable = _data.Insert(values);
                if (dTable.Rows.Count < 1) return -1;

                return (long.Parse(dTable.Rows[0]["ServiceSportID"].ToString()));
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return -1;
            }
        }

        public static long Insert(ServiceSportsInfo info)
        {
            _error = "";
            try
            {
                object[] values = new object[27];
                values[0] = Util.ReplaceNullTo(info.Cmd1, DBNull.Value);
                values[1] = Util.ReplaceNullTo(info.Cmd2, DBNull.Value);
                values[2] = Util.ReplaceNullTo(info.Code1, DBNull.Value);
                values[3] = Util.ReplaceNullTo(info.Code2, DBNull.Value);
                values[4] = Util.ReplaceNullTo(info.Param1, DBNull.Value);
                values[5] = Util.ReplaceNullTo(info.Param2, DBNull.Value);
                values[6] = Util.ReplaceNullTo(info.Param3, DBNull.Value);
                values[7] = Util.ReplaceNullTo(info.Param4, DBNull.Value);
                values[8] = Util.ReplaceNullTo(info.Param5, DBNull.Value);
                values[9] = Util.ReplaceNullTo(info.Param6, DBNull.Value);
                values[10] = Util.ReplaceNullTo(info.Content1, DBNull.Value);
                values[11] = Util.ReplaceNullTo(info.Content2, DBNull.Value);
                values[12] = Util.ReplaceNullTo(info.Content3, DBNull.Value);
                values[13] = Util.ReplaceNullTo(info.Content4, DBNull.Value);
                values[14] = Util.ReplaceNullTo(info.Content5, DBNull.Value);
                values[15] = Util.ReplaceNullTo(info.Content6, DBNull.Value);
                values[16] = Util.ReplaceNullTo(info.Timer1, DBNull.Value);
                values[17] = Util.ReplaceNullTo(info.Timer2, DBNull.Value);
                values[18] = Util.ReplaceNullTo(info.Timer3, DBNull.Value);
                values[19] = Util.ReplaceNullTo(info.MsgType, DBNull.Value);
                values[20] = Util.ReplaceNullTo(info.ContentType, DBNull.Value);
                values[21] = Util.ReplaceNullTo(info.NumOfMsg, DBNull.Value);
                values[22] = Util.ReplaceNullTo(info.ProcessType, DBNull.Value);
                values[23] = Util.ReplaceNullTo(info.ServiceID, DBNull.Value);
                values[24] = info.CreatedBy;
                values[25] = Util.ReplaceNullTo(info.CreatedDate, DBNull.Value);
                values[26] = info.Status;

                DataTable dTable = _data.Insert(values);
                if (dTable.Rows.Count < 1) return -1;

                return (long.Parse(dTable.Rows[0]["ServiceSportID"].ToString()));
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return -1;
            }
        }

        public static bool Update(long serviceSportId, string cmd1, string cmd2, string code1, string code2, string param1, string param2, string param3, string param4, string param5, string param6, string param7, string content1, string content2, string content3, string content4, string content5, string content6, string time1, string time2, string time3, byte msgType, byte contentType, byte numOfMsg, byte processType, string createdBy, string serviceId, DateTime createdDate, byte status)
        {
            _error = "";
            try
            {
                object[] values = new object[27];
                values[0] = serviceSportId;
                values[1] = Util.ReplaceNullTo(cmd1, DBNull.Value);
                values[2] = Util.ReplaceNullTo(cmd2, DBNull.Value);
                values[3] = Util.ReplaceNullTo(code1, DBNull.Value);
                values[4] = Util.ReplaceNullTo(code2, DBNull.Value);
                values[5] = Util.ReplaceNullTo(param1, DBNull.Value);
                values[6] = Util.ReplaceNullTo(param2, DBNull.Value);
                values[7] = Util.ReplaceNullTo(param3, DBNull.Value);
                values[8] = Util.ReplaceNullTo(param4, DBNull.Value);
                values[9] = Util.ReplaceNullTo(param5, DBNull.Value);
                values[10] = Util.ReplaceNullTo(param6, DBNull.Value);
                values[11] = Util.ReplaceNullTo(content1, DBNull.Value);
                values[12] = Util.ReplaceNullTo(content2, DBNull.Value);
                values[13] = Util.ReplaceNullTo(content3, DBNull.Value);
                values[14] = Util.ReplaceNullTo(content4, DBNull.Value);
                values[15] = Util.ReplaceNullTo(content5, DBNull.Value);
                values[16] = Util.ReplaceNullTo(content6, DBNull.Value);
                values[17] = Util.ReplaceNullTo(time1, DBNull.Value);
                values[18] = Util.ReplaceNullTo(time2, DBNull.Value);
                values[19] = Util.ReplaceNullTo(time3, DBNull.Value);
                values[20] = Util.ReplaceNullTo(msgType, DBNull.Value);
                values[21] = Util.ReplaceNullTo(contentType, DBNull.Value);
                values[22] = Util.ReplaceNullTo(numOfMsg, DBNull.Value);
                values[23] = Util.ReplaceNullTo(processType, DBNull.Value);
                values[24] = Util.ReplaceNullTo(serviceId, DBNull.Value);
                values[25] = createdBy;
                values[26] = status;

                return _data.Update(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Update(ServiceSportsInfo info)
        {
            _error = "";
            try
            {
                object[] values = new object[27];
                values[0] = info.ServiceSportID;
                values[1] = Util.ReplaceNullTo(info.Cmd1, DBNull.Value);
                values[2] = Util.ReplaceNullTo(info.Cmd2, DBNull.Value);
                values[3] = Util.ReplaceNullTo(info.Code1, DBNull.Value);
                values[4] = Util.ReplaceNullTo(info.Code2, DBNull.Value);
                values[5] = Util.ReplaceNullTo(info.Param1, DBNull.Value);
                values[6] = Util.ReplaceNullTo(info.Param2, DBNull.Value);
                values[7] = Util.ReplaceNullTo(info.Param3, DBNull.Value);
                values[8] = Util.ReplaceNullTo(info.Param4, DBNull.Value);
                values[8] = Util.ReplaceNullTo(info.Param5, DBNull.Value);
                values[10] = Util.ReplaceNullTo(info.Param6, DBNull.Value);
                values[11] = Util.ReplaceNullTo(info.Content1, DBNull.Value);
                values[12] = Util.ReplaceNullTo(info.Content2, DBNull.Value);
                values[13] = Util.ReplaceNullTo(info.Content3, DBNull.Value);
                values[14] = Util.ReplaceNullTo(info.Content4, DBNull.Value);
                values[15] = Util.ReplaceNullTo(info.Content5, DBNull.Value);
                values[16] = Util.ReplaceNullTo(info.Content6, DBNull.Value);
                values[17] = Util.ReplaceNullTo(info.Timer1, DBNull.Value);
                values[18] = Util.ReplaceNullTo(info.Timer2, DBNull.Value);
                values[19] = Util.ReplaceNullTo(info.Timer3, DBNull.Value);
                values[20] = Util.ReplaceNullTo(info.MsgType, DBNull.Value);
                values[21] = Util.ReplaceNullTo(info.ContentType, DBNull.Value);
                values[22] = Util.ReplaceNullTo(info.NumOfMsg, DBNull.Value);
                values[23] = Util.ReplaceNullTo(info.ProcessType, DBNull.Value);
                values[24] = Util.ReplaceNullTo(info.ServiceID, DBNull.Value);
                values[25] = info.CreatedBy;
                values[26] = info.Status;

                return _data.Update(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Delete(long serviceSportId)
        {
            _error = "";
            try
            {
                object[] values = { serviceSportId };
                return _data.Delete(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static ServiceSportsInfo Select(long serviceSportId)
        {
            _error = "";
            try
            {
                object[] values = { serviceSportId };
                DataTable dTable = _data.Select(values);
                if (dTable.Rows.Count < 1) return null;

                ServiceSportsInfo info = new ServiceSportsInfo(dTable.Rows[0]);
                return info;
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static DataTable SelectAll()
        {
            _error = "";
            try
            {
                return _data.SelectAll();
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static DataTable SearchInfo(string Key)
        {
            _error = "";
            try
            {
                return _data.SearchInfo(Key);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        #endregion
    }
}